Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

feature/node/src/jvmTest/kotlin/org/meshtastic/feature/node/metrics/ChartDrawGuardTest.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.33 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.node.metrics

Tff7b72import T7ee787androidx.compose.ui.geometry.Rect
Tff7b72import T7ee787androidx.compose.ui.graphics.Canvas
Tff7b72import T7ee787androidx.compose.ui.graphics.ImageBitmap
Tff7b72import T7ee787androidx.compose.ui.graphics.Paint
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertEquals
Tff7b72import T7ee787kotlin.test.assertFailsWith

T8b949e/** Covers the save-stack guard around chart drawing (Crashlytics 7744c73d302c0af1676f31f80802d59f). */
Tff7b72class T56d364ChartDrawGuardTest Tb4b4b4{

Tff7b72private Tff7b72fun Td2a8ffnewCanvasTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3Canvas Tff7b72= Te6edf3CanvasTb4b4b4(Te6edf3ImageBitmapTb4b4b4(T79c0ff4Tb4b4b4, T79c0ff4Tb4b4b4)Tb4b4b4)

Tf0883e@Test
Tff7b72fun Td2a8ffguardRebalancesLeakedSavesToEntryDepthTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3newCanvasTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3entryDepth Tff7b72= Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3withRestoreUnderflowGuard Tb4b4b4{
Te6edf3canvasTb4b4b4.Te6edf3saveTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3saveLayerTb4b4b4(Te6edf3RectTb4b4b4(T79c0ff0fTb4b4b4, T79c0ff0fTb4b4b4, T79c0ff4fTb4b4b4, T79c0ff4fTb4b4b4)Tb4b4b4, Te6edf3PaintTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Te6edf3assertEqualsTb4b4b4(Te6edf3entryDepthTb4b4b4, Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffguardSwallowsRestoreUnderflowExceptionTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3newCanvasTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3entryDepth Tff7b72= Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)
T8b949e// Message thrown by android.graphics.Canvas.restore, the crash this guard exists for.
Te6edf3canvasTb4b4b4.Te6edf3withRestoreUnderflowGuard Tb4b4b4{
Tff7b72throw Te6edf3IllegalStateExceptionTb4b4b4(Ta5d6ff"Ta5d6ffUnderflow in restore - more restores than savesTa5d6ff"Tb4b4b4)
Tb4b4b4}
Te6edf3assertEqualsTb4b4b4(Te6edf3entryDepthTb4b4b4, Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffguardRethrowsUnrelatedIllegalStateExceptionTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3newCanvasTb4b4b4(Tb4b4b4)
Te6edf3assertFailsWithTff7b72<Te6edf3IllegalStateExceptionTff7b72> Tb4b4b4{ Te6edf3canvasTb4b4b4.Te6edf3withRestoreUnderflowGuard Tb4b4b4{ Te6edf3errorTb4b4b4(Ta5d6ff"Ta5d6ffunrelatedTa5d6ff"Tb4b4b4) Tb4b4b4} Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffguardRethrowsOtherExceptionTypesTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3newCanvasTb4b4b4(Tb4b4b4)
Te6edf3assertFailsWithTff7b72<Te6edf3IllegalArgumentExceptionTff7b72> Tb4b4b4{
Te6edf3canvasTb4b4b4.Te6edf3withRestoreUnderflowGuard Tb4b4b4{ Tff7b72throw Te6edf3IllegalArgumentExceptionTb4b4b4(Ta5d6ff"Ta5d6ffboomTa5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffguardToleratesStackDrivenBelowSnapshotTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3newCanvasTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3base Tff7b72= Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3saveTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3withRestoreUnderflowGuard Tb4b4b4{
T8b949e// Skia silently ignores restores at the stack floor, so this drives the count below the snapshot.
Te6edf3canvasTb4b4b4.Te6edf3restoreTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3restoreTb4b4b4(Tb4b4b4)
Tb4b4b4}
T8b949e// restoreToCount cannot re-raise a popped stack; it must tolerate the deficit without throwing.
Te6edf3assertEqualsTb4b4b4(Te6edf3baseTb4b4b4, Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ffguardIsNoOpForBalancedDrawingTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3newCanvasTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3entryDepth Tff7b72= Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3withRestoreUnderflowGuard Tb4b4b4{
Te6edf3canvasTb4b4b4.Te6edf3saveTb4b4b4(Tb4b4b4)
Te6edf3canvasTb4b4b4.Te6edf3restoreTb4b4b4(Tb4b4b4)
Tb4b4b4}
Te6edf3assertEqualsTb4b4b4(Te6edf3entryDepthTb4b4b4, Te6edf3canvasTb4b4b4.Te6edf3platformSaveCountTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.15s